package com.dhm.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hrhx.duhongming.config.ConstantExcelPath;
import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice.ThemeType;

@Controller
@RequestMapping(value = "/pageoffice")
public class PageOfficeController {
	
	@RequestMapping(value = "{templates}/{suffix}", method = RequestMethod.GET)
	public String excel(HttpServletRequest request,
						@PathVariable("templates") String templates,
						@PathVariable("suffix") String suffix,
						Object model) {
		PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
		//设置服务器页面
		poCtrl.setServerPage(request.getContextPath()+"/poserver.zz");
		//添加自定义按钮
		poCtrl.addCustomToolButton("保存","Save",1);
		//设置保存页面
		poCtrl.setSaveFilePage("../SaveExcel");
		poCtrl.setCaption("Excel Web编辑器");
		poCtrl.setTheme(ThemeType.Office2010);
		//打开Word文档
		poCtrl.webOpen("../../excel/templates/"+templates+"."+suffix,OpenModeType.xlsNormalEdit,"报表编辑器");
		poCtrl.setTagId("PageOfficeCtrl1");//此行必需
		return "/pageoffice/Excel";
	}
	
	@RequestMapping(value = "SaveExcel", method = RequestMethod.POST)
	public void saveExcelFile(HttpServletRequest request,HttpServletResponse response,Object model) {
		FileSaver fs=new FileSaver(request,response);
		fs.saveToFile(ConstantExcelPath.getExcelTemplatePath()+fs.getFileName());
		fs.close();
	}
}
